package com.caigou.modules.tools.adapter

import android.view.View
import com.alibaba.android.arouter.launcher.ARouter
import com.caigou.comm.base.bus.BusKey
import com.caigou.comm.base.bus.LiveDataBus
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.modules.tools.R
import com.caigou.modules.tools.bean.ActiveItemBean
import com.caigou.modules.tools.databinding.ItemActiveBannerBinding
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

/**
 * @author #Suyghur.
 * Created on 2021/10/27
 */
class ActiveBannerAdapter : BaseBannerAdapter<ActiveItemBean>() {
    override fun bindData(holder: BaseViewHolder<ActiveItemBean>, data: ActiveItemBean, position: Int, pageSize: Int) {
        val binding = ItemActiveBannerBinding.bind(holder.itemView)
        when (data.taskId) {
            11 -> {
                binding.itemActiveFlContainer.setBackgroundResource(R.drawable.img_tools_banner_red_bg)
                binding.itemActiveBtnAction.run {
                    visibility = View.VISIBLE
                    if (data.status == 1) {
                        setBackgroundResource(R.drawable.comm_btn_red)
                        text = "领红包"
                        setOnClickListener {
                            LiveDataBus.get().with(BusKey.GET_RED_PACKAGE).value = Any()
                        }
                    } else {
                        setBackgroundResource(R.drawable.comm_btn_orange)
                        text = "明天再来"
                        isEnabled = false
                    }
                }
            }
            12 -> {
                binding.itemActiveFlContainer.setBackgroundResource(R.drawable.img_tools_banner_score_bg)
                binding.itemActiveBtnAction.visibility = View.GONE
                binding.itemActiveFlContainer.setOnClickListener {
                    ARouter.getInstance()
                        .build(RouterPath.Center.PAGE_DETAIL)
                        .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Center.TAG_SCORE)
                        .navigation()
                }
            }
            13 -> {
                binding.itemActiveFlContainer.setBackgroundResource(R.drawable.img_tools_banner_invite_bg)
                binding.itemActiveBtnAction.visibility = View.GONE
                binding.itemActiveFlContainer.setOnClickListener {
                    ARouter.getInstance()
                        .build(RouterPath.Tools.PAGE_TOOLS)
                        .withString(AppConstants.TARGET_FRAGMENT_TAG, RouterPath.Tools.TAG_INVITE)
                        .navigation()
                }
            }
        }
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.item_active_banner
    }
}